package com.lpc.designmodetest;

/**
 * 功能:建造者模式
 * <p>
 * 描述:
 * <p>
 * Created by lipc0113 on 2018/8/22.
 */
public class User {

    private int id;

    private String name;

    private int age;

    public User(Builder builder) {

        this.id = builder.id;
        this.name = builder.name;
        this.age = builder.age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public static class Builder {

        private int id;

        private String name;

        private int age;

        public Builder setId(int id) {
            this.id = id;
            return this;
        }

        public Builder setName(String name) {
            this.name = name;
            return this;
        }

        public Builder setAge(int age) {
            this.age = age;
            return this;
        }

        public User build() {

            return new User(this);
        }
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
